package com.ruoyi.record.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.record.domain.ErpFinanceRecord;
import com.ruoyi.record.service.IErpFinanceRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 收支记录Controller
 * 
 * @author ruoyi
 * @date 2025-07-21
 */
@RestController
@RequestMapping("/record/record")
public class ErpFinanceRecordController extends BaseController
{
    @Autowired
    private IErpFinanceRecordService erpFinanceRecordService;

    /**
     * 查询收支记录列表
     */
    @PreAuthorize("@ss.hasPermi('record:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(ErpFinanceRecord erpFinanceRecord)
    {
        startPage();
        List<ErpFinanceRecord> list = erpFinanceRecordService.selectErpFinanceRecordList(erpFinanceRecord);
        return getDataTable(list);
    }

    /**
     * 导出收支记录列表
     */
    @PreAuthorize("@ss.hasPermi('record:record:export')")
    @Log(title = "收支记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ErpFinanceRecord erpFinanceRecord)
    {
        List<ErpFinanceRecord> list = erpFinanceRecordService.selectErpFinanceRecordList(erpFinanceRecord);
        ExcelUtil<ErpFinanceRecord> util = new ExcelUtil<ErpFinanceRecord>(ErpFinanceRecord.class);
        util.exportExcel(response, list, "收支记录数据");
    }

    /**
     * 获取收支记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('record:record:query')")
    @GetMapping(value = "/{recordId}")
    public AjaxResult getInfo(@PathVariable("recordId") Long recordId)
    {
        return success(erpFinanceRecordService.selectErpFinanceRecordByRecordId(recordId));
    }

    /**
     * 新增收支记录
     */
    @PreAuthorize("@ss.hasPermi('record:record:add')")
    @Log(title = "收支记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ErpFinanceRecord erpFinanceRecord)
    {
        return toAjax(erpFinanceRecordService.insertErpFinanceRecord(erpFinanceRecord));
    }

    /**
     * 修改收支记录
     */
    @PreAuthorize("@ss.hasPermi('record:record:edit')")
    @Log(title = "收支记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ErpFinanceRecord erpFinanceRecord)
    {
        return toAjax(erpFinanceRecordService.updateErpFinanceRecord(erpFinanceRecord));
    }

    /**
     * 删除收支记录
     */
    @PreAuthorize("@ss.hasPermi('record:record:remove')")
    @Log(title = "收支记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recordIds}")
    public AjaxResult remove(@PathVariable Long[] recordIds)
    {
        return toAjax(erpFinanceRecordService.deleteErpFinanceRecordByRecordIds(recordIds));
    }
}
